package com.xiaoqian.partyembassy.base;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * 项目名称: i尚社区
 * 包: com.dnake.ifationcommunity.adapter
 * 类名称: CommonAdapter
 * 类描述: 适配器基类
 * 创建人: 秦彬
 * 创建时间: 2016-11-30
 * 修改人:
 * 修改时间:
 * 修改备注:
 * 版本: v1.0
 * 
 */
public abstract class CommonAdapter<T> extends BaseAdapter {
	protected LayoutInflater mInflater;
	protected Context mContext;
	protected List<T> mDatas;
	protected Handler mHandler;
	protected int size;

	public CommonAdapter(Context context) {
		mInflater = LayoutInflater.from(context);
		this.mContext = context;
	}
	public CommonAdapter(Context context, List<T> mDatas) {
		mInflater = LayoutInflater.from(context);
		this.mContext = context;
		this.mDatas = mDatas;
	}
	public CommonAdapter(Context context, List<T> mDatas, Handler handler,
                         int size) {
		mInflater = LayoutInflater.from(context);
		this.mContext = context;
		this.mDatas = mDatas;
		this.mHandler = handler;
		this.size = size;
	}
	public List<T> getmDatas() {
		return mDatas;
	}
	public void setmDatas(List<T> mDatas) {
		this.mDatas = mDatas;
		this.notifyDataSetChanged();
	}
	/**
	 * 刷新数据
	 * 
	 * @param mDatas
	 */
	public void refreshDate(List<T> mDatas) {
		this.mDatas = mDatas;
		this.notifyDataSetChanged();
	}
	/**
	 * 加载更多
	 */
	public void loadMore(List<T> newItems) {
		mDatas.addAll(newItems);
		notifyDataSetChanged();
	}
	public void clearItem() {
		//mExecuteItemMap.clear();
		mDatas.clear();
	}
	/**
	 * 删除单独一项
	 * 
	 * @param
	 */
	public int removeListItem(int index) {
		if (mDatas != null) {
			mDatas.remove(index);
			notifyDataSetChanged();
			return mDatas.size();
		}
		return 0;
	}

	@Override
	public int getCount() {
		return mDatas != null ? mDatas.size() : 0;
	}

	@Override
	public T getItem(int position) {
		return mDatas != null ? mDatas.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
